package com.zhengxyou.jetpackdemo.lifecycle_liveData_viewModel.view_model;

import android.util.Log;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

public class CommunicateViewModel extends ViewModel {
    private final String TAG = "CommunicateViewModel";
    private MutableLiveData<String> mNameLiveData;

    public MutableLiveData<String> getName() {
        if (mNameLiveData == null) {
            mNameLiveData = new MutableLiveData<>();
        }
        return mNameLiveData;
    }

    public void setName(String name) {
        if (mNameLiveData != null) {
            Log.e(TAG, "setName==>" + name);
            mNameLiveData.setValue(name);
        }
    }

    @Override
    protected void onCleared() {
        super.onCleared();
        mNameLiveData = null;
    }
}
